package com.cqs.leetcode.offerII;

/**
 * 通过将字符串转化为数字 或运算
 * 通过&运算判断字符串是否重复
 */
public class OfferII005 {
    public int maxProduct(String[] words) {
        int max = 0;
        int[] arr = new int[words.length];
        for (int i = 0; i < words.length; i++) {
            int target = 0;
            for (char c : words[i].toCharArray()) {
                target |= 1 << (c - 'a');
            }
            arr[i] = target;
        }
        for (int i = 0; i < words.length - 1; i++) {
            for (int j = i + 1; j < words.length; j++) {
                if ((arr[i] & arr[j]) == 0) {
                    max = Math.max(max, words[i].length() * words[j].length());
                }
            }
        }
        return max;
    }
}
